package com.itheima.atte.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Configuration
public class FeignHeaderConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //从请求头中获取 认证头信息
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();

        //添加Header  Token
        requestTemplate.header("Authorization", request.getHeader("Authorization"));
    }
}
